package XynLeen.GraduationProject.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import XynLeen.GraduationProject.R;


/**
 * Description:
 */
public class TitleArrowLineItem extends LinearLayout {
    private boolean mShowDetail;
    private boolean mShowImage;
    private String mTitleContent;
    private String mDetailContent;

    private TextView mTitle;
    private TextView mDetailTitle;
    private ImageView mImageView;

    private  int mColorid;
    private Drawable rightimage;

    public TitleArrowLineItem(Context context) {
        this(context, null);
    }

    public TitleArrowLineItem(Context context, AttributeSet attrs) {
        this(context, attrs, -1);
    }

    public TitleArrowLineItem(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray a = context.obtainStyledAttributes(attrs,
                R.styleable.TitleArrowLineItem);

        rightimage =  a.getDrawable(R.styleable.TitleArrowLineItem_bc_rightimaget);
        mShowDetail = a.getBoolean(R.styleable.TitleArrowLineItem_bc_show_detail, false);
        mTitleContent = a.getString(R.styleable.TitleArrowLineItem_bc_arrow_title);
        mDetailContent = a.getString(R.styleable.TitleArrowLineItem_bc_detail);
        mShowImage=a.getBoolean(R.styleable.TitleArrowLineItem_bc_show_image,true);
        mColorid =  a.getColor(R.styleable.TitleArrowLineItem_bc_detail_color,0);
        initLayout(context);
    }

    private void initLayout(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.title_arrow_line_item, this);
        mTitle = (TextView) view.findViewById(R.id.title);
        mDetailTitle = (TextView) view.findViewById(R.id.detail_title);
        mDetailTitle.setVisibility(View.VISIBLE);

        mTitle.setText(mTitleContent);
        mDetailTitle.setText(mDetailContent);

        mImageView=(ImageView) view.findViewById(R.id.right_arrow);
        if(!mShowImage){
         mImageView.setVisibility(GONE);
        }else{
         mImageView.setVisibility(VISIBLE);
        }

        if(mColorid!=0){
            mTitle.setTextColor(mColorid);
        }

        if (rightimage!=null){
            rightimage.setBounds(0, 0, 32, 32);
            mTitle .setCompoundDrawables(rightimage,null,null,null);
        }

    }

    /**
     * 更新详细内容
     * @param detail
     */
    public void setDetail(String detail){
        mDetailTitle.setText(detail);
    }

    /**
     * 更新内容
     * @param title
     */
    public void setTitle(String title){
        mTitle.setText(title);
    }

    public TextView getDetailTextView(){
        return mDetailTitle;
    }

    public String getTextViewVal(){
        return mDetailTitle.getText()+"";
    }
}
